"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const db_1 = __importDefault(require("../utils/db"));
const util_1 = require("./util");
class UserCtl {
    static async getCollection(ctx) {
        const { query } = ctx;
        return await util_1.checkCollection(query, ctx);
    }
    static async list(ctx) {
        const collection = await UserCtl.getCollection(ctx);
        if (collection !== "") {
            const res = await db_1.default.query(collection, {
                where: ctx.query,
            });
            ctx.body = res;
        }
    }
    static async save(ctx) {
        const { request } = ctx;
        const { body } = request;
        const collection = await UserCtl.getCollection(ctx);
        if (collection !== "") {
            body.createTime = utils_1.getCurrentTime("yyyy-mm-dd HH:MM:SS", new Date());
            const res = await db_1.default.insert(collection, body);
            ctx.body = res;
        }
    }
    static async update(ctx) {
        const { request } = ctx;
        const { body } = request;
        const collection = await UserCtl.getCollection(ctx);
        if (collection !== "") {
            const res = await db_1.default.update(collection, body._id, body);
            ctx.body = res;
        }
    }
    static async delete(ctx) {
        const { request } = ctx;
        const { body } = request;
        const collection = await UserCtl.getCollection(ctx);
        if (collection !== "") {
            const res = await db_1.default.delete(collection, body.id);
            ctx.body = res;
        }
    }
}
exports.default = UserCtl;
